<template>
  <div class="exam-box">
    <NavBar></NavBar>
    <div class="top-box">
      <div class="top-title">
        <p class="top-main-title">猿创考试答题系统</p>
        <p class="top-s-title">从此爱上另一种生活</p>
      </div>
    </div>
    <div class="container-box">
      <div class="container-title">选择试卷</div>
      <div class="container">
        <div
          class="container-item"
          v-for="(item, index) in currentList"
          :key="index"
        >
          <div class="item-title">{{ item.paperName }}</div>
          <div class="item-container">{{ item.paperName }}测试卷</div>
          <div class="item-bottom">
            <span class="time">{{ item.paperUptime }}</span>
            <span
              class="iconfont icon-jiantou_xiangyou icon"
              @click="goExamination(item.paperId)"
            ></span>
          </div>
        </div>
      </div>
    </div>
    <div class="block">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="8"
        layout="total, prev, pager, next"
        :total="this.examList.length"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import NavBar from "@/components/NavBar";
import { examList } from "@/api";

export default {
  data() {
    return {
      currentList: null,
      examList: null,
      currentPage: 1,
    };
  },
  mounted() {
    examList().then((res) => {
      this.examList = JSON.parse(JSON.stringify(res));
      this.currentList = this.examList.slice(
        (this.currentPage - 1) * 8,
        this.currentPage * 8
      );
    });
  },
  methods: {
    // 当前页改变时触发
    handleCurrentChange() {
      // console.log(this.currentPage);
      this.currentList = this.examList.slice(
        (this.currentPage - 1) * 8,
        this.currentPage * 8
      );
    },

    // 点击试卷进入考试页面
    goExamination(id) {
      this.$confirm("确定要开始此试卷的考试, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$router.push({
            path: "questions",
            query: {
              id: id,
            },
          });
        })
        .catch(() => {});
      // console.log(id);
    },
  },
  components: {
    NavBar,
  },
};
</script>

<style lang="scss" scoped>
.exam-box {
  min-height: 100vh;
  width: 100%;

  .top-box {
    width: 100%;
    height: 250px;
    padding-top: 20px;
    background: url("@/assets/home_1.jpg") no-repeat;
    background-size: cover;
    background-position: center center;

    .top-title {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      margin: 0 auto;
      width: 585px;
      height: 120px;
      top: 20px;
      color: #7d7d7d;

      .top-main-title {
        font-size: 35px;
        font-weight: 600;
      }

      .top-s-title {
        font-size: 20px;
        color: #888084;
        font-weight: 100;
      }
    }
  }

  .container-box {
    width: 1000px;
    // height: 800px;
    margin: 0 auto;
    margin-top: 50px;
    // background-color: red;

    .container-title {
      font-size: 20px;
      font-weight: 600;
    }

    .container {
      // height: 100%;
      width: 100%;
      // background-color: pink;
      display: flex;
      // justify-content: space-around;
      flex-wrap: wrap;
      margin-top: 20px;

      .container-item {
        width: 210px;
        height: 200px;
        padding: 10px;
        background-color: #fff;
        box-shadow: #d3cfd9 1px 1px 10px 1px;
        margin: 10px;

        .item-title {
          margin: 20px 0;
          font-size: 26px;
          font-weight: 600;
        }

        .item-container {
          height: 52px;
          line-height: 26px;
          color: #8b968d;
          margin-bottom: 30px;
        }

        .item-bottom {
          display: flex;
          justify-content: space-between;
          .time {
            font-size: 10px;
            padding: 2px 5px;
            background-color: rgba(210, 236, 247, 0.5);
            color: #89c3eb;
          }

          .icon {
            font-size: 20px;
            cursor: pointer;
          }
        }
      }
    }
  }

  .block {
    width: 1000px;
    margin: 20px auto;

    ::v-deep .el-pagination {
      float: right;
    }
  }
}
</style>
